/**
 * 将法律法规中浏览器兼容性标签 IE7 改到Edge，以便稅易的内嵌浏览器能正确显示格式（忽略里面有个UL没有对应的bug）
 * author sunny
 * 2018-11-05
 */

var fs = require("fs") ;
var total = 0, success = 0;

function processFile(fp) {
    var stats = fs.statSync(fp);
    if (stats.isDirectory()) {
        console.log(fp);
        var ds = fs.readdirSync(fp);
        ds.forEach((v)=>{
            var f_path = fp + '/' + v; 
            processFile(f_path);
        });
    } else {
        total++;
        var c = fs.readFileSync(fp, {encoding: "utf-8"});
        c = c.replace(/"IE=7"/, "\"IE=Edge\"");
        fs.writeFileSync(fp, c);
        console.log(fp + " replace success");
        success++;
    }
}

function main(dpath) {
    if (!fs.existsSync(dpath)) {
        console.log("path: " + dpath + " invalid");
    } else {
        processFile(dpath);
    }
    console.log("total => " + total + " success => " + success);
}


var dirpath = "D:/law/to/store/directory";
main(dirpath);